// RedJey Graphics User Interface Library for J2ME Platform.
// Copyright (C) 2008 Yevgen Krapiva
//
// This library is free software; you can redistribute
// it and/or modify it under the terms of the
// GNU Lesser General Public License as published
// by the Free Software Foundation; either version 3.0
// of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//

package com.incrediblesoft.redjey.event;

/**
 * @author Yevgen Krapiva<br>
 *         Homepage: http://code.google.com/p/redjey/<br>
 *         Feedback: ykrapiva@gmail.com<br>
 *         Copyright (C) 2008 Yevgen Krapiva<br>
 */

import com.incrediblesoft.redjey.Component;

public class AbstractEvent
{
    /**
     * Event types. Used to avoid the use of instanceof instruction
     */
    public final static int MOUSE_EVENT = 0;
    public final static int PAINT_EVENT = 1;
    public final static int ACTION_EVENT = 2;
    public final static int FOCUS_EVENT = 3;
    public final static int KEY_EVENT = 4;

    /**
     * Event type (Mouse, Paint, Action etc.)
     */
    private int eventType;

    /**
     * Event ID within eventType context
     */
    int id;
    /**
     * Object the event belong to
     */
    Component source;
    /**
     * This flag means that event must no be processed further
     */
    boolean isConsumed;

    /**
     * Default constructor
     * @param source Source
     * @param id Event ID
     * @param eventType Type of event (Mouse, Paint, Action etc.)
     */
    public AbstractEvent(Component source, int id, int eventType)
    {
        this.eventType = eventType;
        this.source = source;
        this.id = id;
    }

    /**
     * Returns event's source
     * @return Source
     */
    public Component getSource()
    {
        return source;
    }

    /**
     * Sets source of event
     * @param source Source
     */
    public void setSource(Component source)
    {
        this.source = source;
    }

    /**
     * Returns event id
     * @return
     */
    public int getID()
    {
        return id;
    }

    /**
     * Sets event id
     * @param id ID
     */
    public void setID(int id)
    {
        this.id = id;
    }

    /**
     * Returns wether this event is already consumed
     * @return true/false
     */
    public boolean isConsumed()
    {
        return isConsumed;
    }

    /**
     * Consumes this event
     */
    public void consume()
    {
        isConsumed = true;
    }

    /**
     * Returns the type of event
     * @return Event type (Mouse, Paint, Action etc.)
     */
    public int getEventType()
    {
        return eventType;
    }
}
